package com.happy3w.ssp.schoolmatehome.repository;

import com.happy3w.ssp.schoolmatehome.entity.ClockInRecord;
import com.happy3w.ssp.schoolmatehome.service.record.ClockInRecordSummary;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface ClockInRecordRepository extends JpaRepository<ClockInRecord, Long> {
    @Query(value = "SELECT r.id, cit.id as template_id, cit.name as template_name,cit.icon_name as template_icon_name," +
            "r.clock_in_date, r.the_weather, r.the_mood, r.summary from clock_in_record r " +
            "left join clock_in_template cit on r.template_id=cit.id " +
            "WHERE r.owner_id = :ownerId order by r.clock_in_date desc", nativeQuery = true)
    List<ClockInRecordSummary> findByOwnerId(@Param("ownerId") Long ownerId);
}